home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gwu / open.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-30  |  7.6 KB  |  284 lines

  1. /*
  2.     GWAda Development Environment for 386/486 PCs   
  3.     Copyright (C) 1993, Arthur Vargas Lopes  & Michael Bliss Feldman
  4.                         vlopes@vortex.ufrgs.br mfeldman@seas.gwu.edu
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; version 2 of the License.    
  9.  
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with this program; if not, write to the Free Software
  18.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20.  
  21. /* open.c */
  22.  
  23. #include "externs.h"
  24.  
  25.  
  26.  
  27.     
  28. void AVL_GET_FILE_NAMES(AVL_SOURCE_PTR s,char *pathn)
  29. {
  30.    struct find_t  c_file;
  31.    int n = 0;
  32.  
  33.    s -> no_files = 0;
  34.  
  35.    /* find first .ada file in current directory */
  36.    if (_dos_findfirst( pathn, _A_NORMAL, &c_file ))
  37.            return;    
  38.  
  39.    s -> no_files += 1;
  40.  
  41.    /* find the rest of the .ada files */
  42.    while( _dos_findnext( &c_file ) == 0 )
  43.         s -> no_files += 1;
  44.    if (_dos_findfirst( pathn , _A_NORMAL, &c_file ))
  45.            return;
  46.    sprintf(s -> name[n++],"%-12s",c_file.name);
  47.     
  48.    /* find the rest of the .ada files */
  49.    while( _dos_findnext( &c_file ) == 0 )
  50.            if (n >= AVL_TOOL_MAX)  {
  51.                AVL_ERROR("Too many sources scanned...");
  52.                break;
  53.                }
  54.            else
  55.             sprintf(s -> name[n++],"%-12s",c_file.name);
  56. }
  57.  
  58.  
  59.  
  60.  
  61. void AVL_SHOW_SOURCES(AVL_SOURCE_PTR w, int cols)
  62. {
  63.     short i, first, last, k;    
  64.     short co;
  65.     char msg[35];
  66.     char fmt[20];
  67.     sprintf(fmt," %cc %c-%ds", '%', '%', cols);
  68.     k = avl_cur_source / 15;
  69.     first = k * 15;
  70.     last = first + 14;
  71.     if (last >= avl_size) 
  72.         last = avl_size - 1;
  73.     _settextposition(1,1);
  74.     _outtext("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
  75.     k = 1;
  76.     for(i = first; i <= last; ++i)  {
  77.         _settextposition(k,2);
  78.         if (i == avl_cur_source)
  79.             co = _settextcolor(avl_men_ready);
  80.         else
  81.             co = _settextcolor(avl_men_letter);
  82.         ++k;
  83.         _outtext(w -> name[i]);
  84.         }
  85.     _settextcolor(co);
  86. }
  87.                 
  88. int AVL_SOURCES(AVL_SOURCE_PTR w, int r, char *pathn)
  89. {
  90.         short x ;
  91.         short no = 0;
  92.         short ch, cols = 0, rows;
  93.         AVL_WIN_PTR hw, hw2;
  94.         if (r < 16)
  95.             rows = r;
  96.         else 
  97.             rows = 15;
  98.         avl_size = r;
  99.  
  100.         cols = 16;
  101.         hw2 = AVL_MAKE_WINDOW("",15,55,15+7,55+24,avl_wnd_bk_color,avl_wnd_color);
  102.         _outtext(" Use the arrow keys to\n");
  103.         _outtext(" go  over  the  files.\n");
  104.         _outtext("\n");
  105.         _outtext(" Press  <enter>  to\n");
  106.         _outtext(" select  a  file.\n");
  107.         _outtext(" Press ESC to  cancel.");
  108.         hw = AVL_MAKE_WINDOW(pathn,3,avl_menu[0].c,3+rows+1,avl_menu[0].c+cols+5,avl_wnd_bk_color,avl_wnd_color);
  109.  
  110.         while ( 1 )  {
  111.             AVL_SHOW_SOURCES(w,cols-4);
  112.             ch = getch();
  113.             if (ch == 13) {
  114.                 AVL_DEL_WINDOW(hw);
  115.                 AVL_DEL_WINDOW(hw2);
  116.                 return avl_cur_source;
  117.                 }
  118.             else {
  119.                 if (ch == 0 || ch == 0xE0) {
  120.                     ch = getch();
  121.                     switch( ch ) {
  122.                         case 73 : /* Page Up */ 
  123.                             avl_cur_source -= rows;
  124.                             if (avl_cur_source < 0)  
  125.                                 avl_cur_source = avl_size - 1;
  126.                             break;
  127.                         case 72 : /* Up */ 
  128.                             if (--avl_cur_source < 0)  
  129.                                 avl_cur_source = avl_size - 1;
  130.                             break;
  131.                         case 81 : /* Page Down */ 
  132.                             avl_cur_source += rows;
  133.                             if (avl_cur_source >= avl_size)
  134.                                 avl_cur_source = 0;
  135.                             break;
  136.                         case 80 : /* Down */ 
  137.                             if (++avl_cur_source >= avl_size)
  138.                                 avl_cur_source = 0;
  139.                             break;
  140.                         default : putchar(7); break;
  141.                         }
  142.                     continue;
  143.                     }
  144.                 if (ch == 27)  {
  145.                     AVL_DEL_WINDOW(hw);
  146.                     AVL_DEL_WINDOW(hw2);
  147.                     return -1;
  148.                     }
  149.                 putch(7);
  150.                 continue;
  151.                 }
  152.             }
  153. }            
  154.  
  155.  
  156.  
  157. void AVL_DO_LOAD()
  158. {
  159.     AVL_EDIT_WINDOW_PTR w;
  160.     AVL_WIN_PTR m;
  161.     AVL_SOURCE_SIZE t;
  162.     short n = 0, i=1000;
  163.     char s[161];
  164.     static int first = 0;
  165.     static char fname[161];
  166.     static char lastfn[121];
  167.     static char *msg = " GWAda - Open which file? ";
  168.     w = &avl_windows[avl_window];
  169.     m = AVL_MAKE_WINDOW(msg,7,4,9,5+62,avl_wnd_bk_color,avl_wnd_color);
  170.     if (first == 0)
  171.         sprintf(lastfn,"%s%c*.ada",avl_dir_sources,92);
  172.     first = 1;
  173.     strcpy(fname,lastfn);
  174.     if (AVL_PROMPT(1,1,fname,60)) {
  175.         AVL_DEL_WINDOW(m);
  176.         return;
  177.         }
  178.  
  179.     strcpy(lastfn,fname);
  180.     for(i = 0; i < strlen(fname); ++i)
  181.         if (fname[i] == '*' || fname[i] == '?')  {
  182.             i = -20;
  183.             break;
  184.             }
  185.     if (i > 0)
  186.         strcpy(w -> file_name, fname);
  187.     else {
  188.         AVL_GET_FILE_NAMES(&t,fname);
  189.         if (t.no_files == 0)  {
  190.             w -> file_name[0] = '\0';
  191.             sprintf(s,"Can't find any file under \'%s\'",fname);
  192.             AVL_ERROR(s);
  193.             }
  194.         else  {        
  195.             n = AVL_SOURCES(&t,t.no_files,fname);
  196.             if (n >= 0)  { 
  197.                 for(i = strlen(fname) - 1; t.no_files > 1 && i > 0; --i)  {
  198.                     if ((fname[i] == 92 || fname[i] == '\\') && i > 0) {
  199.                         fname[i+1] = '\0';
  200.                         i = -10;
  201.                         break;
  202.                         }
  203.                     }
  204.                 if (i < -1)
  205.                     sprintf(w -> file_name, "%s%s",fname,t.name[n]);
  206.                 else 
  207.                     sprintf(w -> file_name, "%s",t.name[n]);
  208.                 }
  209.             else 
  210.                 w -> file_name[0] = '\0';
  211.             }
  212.         }
  213.     AVL_DEL_WINDOW(m);
  214. }
  215.  
  216.                 
  217. void AVL_OPEN()
  218. {
  219.         AVL_LINE_PTR head = NULL, temp;
  220.         int x ;
  221.         int no = 0;
  222.         int ch, back;
  223.         char msg[80];
  224.         FILE *fp, *fopen();
  225.         AVL_WIN_PTR hw;
  226.         AVL_EDIT_WINDOW_PTR w;
  227.         if (avl_nwindows >= AVL_MAX_WINDOWS) {
  228.             sprintf(msg,"Can't open more than %d text files.", AVL_MAX_WINDOWS);
  229.             AVL_ERROR(msg);
  230.             return;
  231.             }
  232.         back = avl_window;
  233.         avl_window = avl_nwindows++;
  234.         w = &avl_windows[avl_window];
  235.         w -> head = w -> current_line = NULL;
  236.         AVL_DO_LOAD();
  237.         if (strlen(w -> file_name) == 0) {
  238.             --avl_nwindows;
  239.             avl_window = back;
  240.             return;
  241.             }
  242.         _settextrows( 25 );
  243.         _clearscreen( _GCLEARSCREEN );
  244.         AVL_LOAD_FILE(w -> file_name);
  245. }
  246.  
  247. void AVL_OPEN_ERROR()
  248. {
  249.         AVL_LINE_PTR head = NULL, temp;
  250.         int x ;
  251.         int no = 0;
  252.         int ch, back;
  253.         char *p, msg[80];
  254.         FILE *fp, *fopen();
  255.         AVL_WIN_PTR hw;
  256.         AVL_EDIT_WINDOW_PTR w;
  257.         if (avl_nwindows >= AVL_MAX_WINDOWS) {
  258.             sprintf(msg,"Can't open more than %d text files.", AVL_MAX_WINDOWS);
  259.             AVL_ERROR(msg);
  260.             return;
  261.             }
  262.         back = avl_window;
  263.         w = &avl_windows[avl_window];
  264.         for(x = strlen(current_file_name) - 1; current_file_name[x] != 92 && 
  265.             ¤t_file_name[x] != current_file_name; --x);
  266.         if (current_file_name[x] == 92) 
  267.             p = ¤t_file_name[x] + 1;
  268.         else 
  269.             p = ¤t_file_name;
  270.         for(x = 0; *(p+x) != '.' && *(p+x) != '\0'; ++x)
  271.             msg[x] = *(p+x);
  272.         msg[x] = '.';
  273.         msg[x+1] = 'l';
  274.         msg[x+2] = 'i';
  275.         msg[x+3] = 's';
  276.         msg[x+4] = '\0';
  277.         avl_window = avl_nwindows++;
  278.         w = &avl_windows[avl_window];
  279.         strcpy(w -> file_name,msg);
  280.         w -> head = w -> current_line = NULL;
  281.         _settextrows( 25 );
  282.         _clearscreen( _GCLEARSCREEN );
  283.         AVL_LOAD_FILE(w -> file_name);
  284. }
  285.